﻿/// <reference path="../script/vswd-ext_2.0.2.js" />
function addTab(tabPanel, id, url,icoCls,helpPanel) {
    var tab = tabPanel.getComponent(id);

    var href = url;

    var refreshButton = new Ext.Button({
        text: '刷新窗口',
        type: "button",
        icon: "/images/icons/arrow_refresh.png",
        listeners: {
            click: function (button, e) {
                Ext.DomQuery.selectNode('iframe', button.ownerCt.ownerCt.getEl().dom).contentWindow.location.replace(href);
                e.stopEvent();
            }
        }
    });

    var openNewWindowButton = new Ext.Button({
        text: '新页面打开',
        type: "button",
        icon: "/images/icons/table_link.png",
        listeners: {
            click: function (button, e) {
                window.open(href, "_blank");
                e.stopEvent();
            }
        }
    });
    
    var removePageButton = new Ext.Button({
        text: '关闭窗口',
        type: "button",
        icon: "/images/icons/tab_delete.png",
        listeners: {
            click: function (button, e) {
                tabPanel.remove(tab);
            }
        }
    });

    if (!tab) {
        tab = tabPanel.add({
            id: id,
            title: id,
            closable: true,
            autoLoad: {
                showMask: true,
                url: url,
                mode: 'iframe',
                maskMsg: '数据处理中，请稍候... '
            },
            tbar: new Ext.Toolbar({
                items: ['->', refreshButton, '-', removePageButton]
            })
        });
        tabPanel.setActiveTab(tab);
    }
    else {
        //        tabPanel.remove(tab);
        //        tab = tabPanel.add({
        //            id: id,
        //            title: id,
        //            closable: true,
        //            autoLoad: {
        //                showMask: true,
        //                url: url,
        //                mode: 'iframe',
        //                maskMsg: '数据处理中，请稍候...'
        //            }
        //        });
        tabPanel.setActiveTab(tab);

        //tab.getUpdater().refresh();
    }

    //  helpPanel.load("http://localhost:8888/pages/common/GetHelp.aspx?url=" + url);
}